<extend name="Manage/themes/default/base" />
<block name="main">
    <style>
        #cat .layui-input-inline{
            width: 188px;
        }
    </style>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <table class="table-form">
                    <tr>
                        <td width="100" align="right" class="td-title">
                            <span class="x-red">*</span>原密码：
                        </td>
                        <td>
                            <input type="password" id="old_password" placeholder="请输入原密码" autocomplete="off" class="layui-input" size="40">
                        </td>
                    </tr>

                    <tr>
                        <td width="100" align="right" class="td-title">
                            <span class="x-red">*</span>新密码：
                        </td>
                        <td>
                            <input type="password" id="new_password" placeholder="请输入新密码" autocomplete="off" class="layui-input" size="40">
                        </td>
                    </tr>

                    <tr>
                        <td align="right" class="td-title">
                            <span class="x-red">*</span>确认新密码：
                        </td>
                        <td>
                            <input type="password" id="confirm_password" placeholder="请输入确认密码" autocomplete="off" class="layui-input" size="40">
                        </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td>
                            <button class="layui-btn layui-btn-danger layui-btn-lg" onclick="Pages.sureSave()" type="button">确定保存</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <script>
        var form;

        layui.use(['form'], function(){
            form = layui.form;
        });

        var Pages = {
            canOperate:true, //能否操作
            sureSave:function(){
                if(!Pages.canOperate){
                    return false;
                }
                var fields = {};
                fields.old_password = $('#old_password').val();
                fields.new_password = $('#new_password').val();
                fields.confirm_password = $('#confirm_password').val();
                if(!fields.old_password){
                    VK.error('请输入原密码');
                    return false;
                }
                if(!fields.new_password){
                    VK.error('请输入新密码');
                    return false;
                }
                if(!fields.confirm_password){
                    VK.error('请输入确认密码');
                    return false;
                }
                if(fields.new_password != fields.confirm_password){
                    VK.error('新密码和确认密码不一致');
                    return false;
                }
                var loading = VK.load();
                Pages.canOperate = false;
                VK.QAjax(VK.U('password'),'put',fields,function (res) {
                    VK.closeLoad(loading);
                    if (res.status != 200){
                        Pages.canOperate = true;
                        VK.error(res.msg);
                        return false;
                    }
                    VK.success('修改成功');
                    setTimeout(function(){
                        top.location.href= VK.U('login');
                    },1500);
                },function (res) {
                    VK.closeLoad(loading);
                    Pages.canOperate = true;
                    VK.error('系统出错稍后再试');
                });
            },
            cancelSave:function(){
                VK.closeNowPage();
            }
        }

    </script>
</block>